﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.OracleClient;
using BCNPCObject.DB;
using DbLinq;
using DbLinq.Oracle;
using CMISLibrary.Entities;
using CMISLibrary;


namespace BCNPCObject.EXCEL
{
    public class cls_D_TNGAN_VIEN_Controller
    {
        #region   Atributes

        //private DataSet CMIS_Header = new CMISOutputParameter();
        private D_TNGAN_VIEN info;

        #endregion

        #region   Constructor

        public cls_D_TNGAN_VIEN_Controller()
        {
            info = new D_TNGAN_VIEN();
        }
        public cls_D_TNGAN_VIEN_Controller(D_TNGAN_VIEN Info)
        {
            this.info = Info;
        }

        #endregion

        #region   Properties

        public D_TNGAN_VIEN pInfor
        {
            get { return info; }
            set { info = value; }
        }
        #endregion
        #region Methods
        public DataSet select_ThuNganVien(string ma_dviqly)
        {
            DataTable dt = new DataTable();
            DataSet ds = new DataSet();
            try
            {
                var result = from a in CMIS2.DB.D_TNGAN_VIEN
                             where a.MA_DVIQLY == ma_dviqly && a.TINH_TRANG == 1
                             select new
                             {
                                 a.MA_DVIQLY,
                                 a.MA_TNGAN,
                                 a.TEN_TNGAN,
                                 SEARCH = a.MA_TNGAN + " _*_ " + a.TEN_TNGAN
                             };
                
                    dt = Utility.LINQToDataTable(result);
                    ds.Tables.Add(dt);
                    return ds;
            }
            catch (Exception ex)
            {
                //maloi = ex.ToString();
                CMIS2.ResetDB(); return null;
            }
        }
        public DataSet select_ThuNganVien_baocao(string ma_dviqly)
        {
            DataTable dt = new DataTable();
            DataSet ds = new DataSet();
            try
            {
                var BBthungan = (from b in CMIS2.DB.CN_BB_GTHU
                                where b.MA_DVIQLY.Contains(ma_dviqly)
                                select new { b.MA_TNGAN,b.MA_DVIQLY}).Distinct().ToList();
                var result = from a in CMIS2.DB.D_TNGAN_VIEN.ToList()
                             where a.MA_DVIQLY.Contains(ma_dviqly) && a.TINH_TRANG == 1
                             join a1 in BBthungan on new { a.MA_TNGAN, a.MA_DVIQLY } equals new { a1.MA_TNGAN, a1.MA_DVIQLY }
                             select new
                             {
                                 a.MA_DVIQLY,
                                 a.MA_TNGAN,
                                 a.TEN_TNGAN,
                                 SEARCH = a.MA_TNGAN + " _*_ " + a.TEN_TNGAN
                             };

                dt = Utility.LINQToDataTable(result);
                ds.Tables.Add(dt);
                return ds;
            }
            catch (Exception ex)
            {
                //maloi = ex.ToString();
                CMIS2.ResetDB(); return null;
            }
        }
        #endregion
    }
}
